package jsyf.oa.web.report.mineCustomer;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.report.mineCustomer.CustomerReportFacade;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by 92852 on 2018/4/5.
 * 吴江华
 */
@Api(value = "客户报表接口", description = "客户报表接口")
@Controller
@RequestMapping("/customerReport")
public class CustomerReportController {
    @Resource
    private CustomerReportFacade customerReportFacade;

    @ResponseBody
        @RequestMapping(value = "/getForPersonalCustomerList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询个人客户列表",
            notes = "查询个人客户列表 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{userId:'',dateTime:'',key:''}", dataType = "String", paramType = "body")
    public void getForPersonalCustomerList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = this.customerReportFacade.getForPersonalCustomerList(jsonData);
        if (null != records) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjHourRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }

    }

    @ResponseBody
    @RequestMapping(value = "/getForDepartCustomerList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询部门客户列表",
            notes = "查询部门客户列表 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{userId:'',dateTime:''}", dataType = "String", paramType = "body")
    public void getForDepartCustomerList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = this.customerReportFacade.getForDepartCustomerList(jsonData);
        if (null != records) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }

    }

    @ResponseBody
    @RequestMapping(value = "/getForCompanyCustomerList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询公司客户列表",
            notes = "查询公司客户列表 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{userId:'',dateTime:''}", dataType = "String", paramType = "body")
    public void getForCompanyCustomerList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = this.customerReportFacade.getForCompanyCustomerList(jsonData);
        if (null != records) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }

    }

    @ResponseBody
    @RequestMapping(value = "/getForGroupCustomerList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询集团客户列表",
            notes = "查询集团客户列表 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{userId:'',dateTime:''}", dataType = "String", paramType = "body")
    public void getForGroupCustomerList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = this.customerReportFacade.getForGroupCustomerList(jsonData);
        if (null != records) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }

    }

    @ResponseBody
    @RequestMapping(value = "/getAllCustomerList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询所有客户列表",
            notes = "查询所有客户列表 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{userId:'',key:''}", dataType = "String", paramType = "body")
    public void getAllCustomerList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = this.customerReportFacade.getAllCustomerList(jsonData);
        if (null != records) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjHourRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }

    }
    @ResponseBody
    @RequestMapping(value = "/getAllCustomerListByCompanyId.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "根据公司ID查询所有客户列表",
            notes = "根据公司ID查询所有客户列表",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{userId:'',key:'',dateTime:''}", dataType = "String", paramType = "body")
    public void getAllCustomerListByCompanyId(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = this.customerReportFacade.getAllCustomerListByCompanyId(jsonData);
        if (null != records) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjHourRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }

    }
    @ResponseBody
    @RequestMapping(value = "/getDepartByCompanyId.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询集团下部门",
            notes = "查询集团下部门 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{companyId:'',dateTime:''}", dataType = "String", paramType = "body")
    public void getForDepartByCompanyId(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = this.customerReportFacade.getDepartByCompanyId(jsonData);
        if (null != records) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }

    }

    @ResponseBody
    @RequestMapping(value = "/getCustomerById.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询客户详细信息",
            notes = "查询客户详细信息 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{customerId:''}", dataType = "String", paramType = "body")
    public void getCustomerById(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = this.customerReportFacade.getCustomerById(jsonData);
        if (null != records) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjHourRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }

    }

    /*保存修改客户信息*/
    @ResponseBody
    @RequestMapping(value = "/saveCustomerInfo.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "保存修改客户信息",
            notes = "保存修改客户信息",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{'customer':''}", dataType = "String", paramType = "body")
    public void saveIntentCustomerInfo(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = customerReportFacade.saveIntentCustomerInfo(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjHourRespond(records));
    }

}
